﻿@using Web7.Container.Models
@using Web7.Core.Security
@model OwnerPermissionRecordContent
@helper  RenderHtml(Permission item, IEnumerable<PermissionRecord> OwnerPermissionRecords)
    {
    <fieldset>
        <legend>@item.Name</legend>
        <table width="500">
            <tr>
                <td>
                    Permission
                </td>
                <td>
                    Allow
                </td>
            </tr>
            <tr>
                <td>@item.Description
                </td>
                <td>@Html.CheckBox("PermissionIds", OwnerPermissionRecords.Any(p => p.ActionId == item.Id) , new { value = item.Id })
                </td>
            </tr>
        </table>
    </fieldset>
}
@using (Html.BeginForm("Index", "PermissionRecord", FormMethod.Post))
{
    <label>
        Rights</label>
    
    switch (Model.OwnerType)
    {
        case PermissionOwnerType.User:
            {
                var user = Model.Content as OwnerPermissionRecord<User>;
                foreach (var item in user.PermissionRecords)
                {
    @RenderHtml(item, user.OwnerPermissionRecords);
                }
            }
            break;
        case PermissionOwnerType.Role:
            {
                var role = Model.Content as OwnerPermissionRecord<Role>;
                foreach (var item in role.PermissionRecords)
                {
    @RenderHtml(item, role.OwnerPermissionRecords);
                }
            }
            break;
    }
    <input type="submit" name="PermissionRecord" value="submit" />
}
